$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/buserinfo/queryUserVital',
        datatype: "json",
        colModel: [			
			// { label: 'ID', name: 'orderId', index: 'order_id',align: "center", width: 100, key: true,
			// 	formatter:function(value,options,rowData){
			// 		return "<a onclick=vm.openInfo('"+value+"')>"+value+"</a>";
			// 	}
			// },
            { label: '公众号', name: 'gzhName', index: 'gzhName',align: "center", width:50 },
			{ label: '用户总数', name: 'userCount', index: 'userCount',align: "center", width: 50 },

			{ label: '今日新增首次接触', name: 'jtxzCount', index: 'jtxzCount',align: "center", width: 50},

			{ label: '会员总数', name: 'yxhyCount', index: 'yxhyCount',align: "center", width: 50 },
			{ label: '赠送总数', name: 'zshyCount', index: 'zshyCount',align: "center", width: 50 },
			{ label: '今日赠送', name: 'jtzshyCount', index: 'jtzshyCount',align: "center", width: 50 },
            { label: '支付总数', name: 'zfhyCount', index: 'zfhyCount',align: "center", width: 50},
			{ label: '今日支付', name: 'jtzfhyCount', index: 'jtzfhyCount',align: "center", width: 50},

			{ label: '关注总数', name: 'gzCount', index: 'gzCount',align: "center", width: 50},
			{ label: '今日关注', name: 'jtgzCount', index: 'jtgzCount',align: "center", width: 50},
			{ label: '取关总数', name: 'qgCount', index: 'qgCount',align: "center", width: 50},
			{ label: '今日取关', name: 'jtqgCount', index: 'jtqgCount',align: "center", width: 50},
			{ label: '24小时活跃', name: 'd1hyCount', index: 'd1hyCount',align: "center", width: 50},
			{ label: '72小时活跃', name: 'd3hyCount', index: 'd3hyCount',align: "center", width: 50},
        ],
		viewrecords: true,
        height: "100%",
        rowNum: 18,
		rowList : [18,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });


	$.ajax({
		type: "POST",
		async:false,
		url: baseURL + 'sys/buserinfo/getUserGzhList',
		contentType: "application/json",
		success: function(r){
			if(r.code==0){
				//vm.bbrandinfo=r.brandInfo;
				$("#selectUserGzhList").append(
					"<option value=''>全部平台</option>");
				for(var i=0;i<r.userGzhList.length;i++){
					$("#selectUserGzhList").append(
						"<option value=" + r.userGzhList[i].gzhCode +">"+ r.userGzhList[i].gzhName+"</option>");
				}
			}
		}
	});
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bOrderInfo: {},
		q:{
			date:null,
			gzhCode:''
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		openInfo: function (e) {
			var orderId =e;
			if(orderId == null){
				return ;
			}
			vm.showList = false;
			vm.title = "修改";

			vm.getInfo(orderId)
		},
		getInfo: function(orderId){
			$.get(baseURL + "sys/borderinfo/info/"+orderId, function(r){
                vm.bOrderInfo = r.bOrderInfo;
				// if(vm.bOrderInfo.itemId==1){
				// 	vm.bOrderInfo.itemId="半年会员";
				// }else if(vm.bOrderInfo.itemId==2){
				// 	vm.bOrderInfo.itemId= "一年会员";
				// }else if(vm.bOrderInfo.itemId==3){
				// 	vm.bOrderInfo.itemId= "三年会员";
				// }
                $("#drawback").hide();
				if(vm.bOrderInfo.transStatus==0){
					vm.bOrderInfo.transStatusText="待支付";
				}else if(vm.bOrderInfo.transStatus==1){
                    vm.bOrderInfo.transStatusText="已支付";
                    $("#drawback").show();
                }else if(vm.bOrderInfo.transStatus==2){
                    vm.bOrderInfo.transStatusText="已退款";
                }

            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
				postData:{"stareDate":vm.q.stareDate,"endDate":vm.q.endDate,"gzhCode":vm.q.gzhCode}
            }).trigger("reloadGrid");
		}
	}
});